#!/usr/bin/python3.8.9
# -*- coding: utf-8 -*-

# @Author  : Tina Yu
# @Time    : 2021-7-17 18:28
'''
练习9-14【彩票】
'''
from random import choice

'''
练习9-14【彩票】
'''


def get_warnning_ticket(lottery_choices):
    """
    随机生成中奖号码，号码的规则：4位，不重复
    :param lottery_choices:
    :return:
    """
    warnning_ticket = []
    while len(warnning_ticket) < 4:
        lottery_choice = choice(lottery_choices)
        if lottery_choice not in warnning_ticket:
            warnning_ticket.append(lottery_choice)

    print(f"中奖号码为：{warnning_ticket}")
    return warnning_ticket


def your_choice(lottery_choices):
    """
    抽取彩票
    :param lottery_choices:
    :return:
    """
    your_ticket = []
    while len(your_ticket) < 4:
        lottery_choice = choice(lottery_choices)
        if lottery_choice not in your_ticket:
            your_ticket.append(lottery_choice)

    print(f"您抽取的彩票号码为：{your_ticket}")
    return your_ticket


def check_ticket(warnning_ticket, your_ticket):
    """
    查验是否中奖
    :param warnning_ticket:
    :param your_ticket:
    :return:
    """
    for element in your_ticket:
        if element not in warnning_ticket:
            return False
    return True


lottery_choices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 'a', 'b', 'c', 'd', 'e']
warnning_ticket = get_warnning_ticket(lottery_choices)

get_it = False
times = 0
max_time = 10000
while not get_it:
    your_ticket = your_choice(lottery_choices)
    get_it = check_ticket(warnning_ticket, your_ticket)
    times += 1
    if times > max_time:
        break
if get_it:
    print(f"恭喜您中奖了！")
    print(f"您抽取的彩票号码为：{your_ticket}")
    print(f"共计抽取了 {times} 次")
else:
    print(f"很遗憾，共计试了{times}次，仍然没能中奖！")
